<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <view class="jtop_c">个人信息</view>
    </view>
    <view class="tophr"></view>

    <view class="ubs">
      <view class="ub uba" @tap="user_head">
        <view class="ub_l">头像</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <image :src="user.avatar" class="ub_tx"></image>
      </view>
      <view class="ub" @tap="user_edit_name">
        <view class="ub_l">姓名</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t">{{ user.realName }}</view>
      </view>
      <view class="ub" @tap="user_edit_sex">
        <view class="ub_l">性别</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t"
          >{{ user.gender == 1 ? '女' : '' }}{{ user.gender == 2 ? '男' : ''
          }}{{ user.gender == -2 ? '保密' : '' }}</view
        >
      </view>
    </view>

    <view class="ubs">
      <view class="ub" @tap="user_edit_phone">
        <view class="ub_l">电话</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t">{{ user.phone }}</view>
      </view>
      <view class="ub" @tap="user_edit_mail">
        <view class="ub_l">邮箱</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t">{{ user.email }}</view>
      </view>
    </view>

    <view class="ubs" @tap="user_edit_company">
      <view class="ub">
        <view class="ub_l">所属企业</view>
        <image src="../../static/img/user/ic_right.png" class="ub_jt"></image>
        <view class="ub_t" v-if="this.usert.corpBaseInfoResponse.fullName"
          >{{ this.usert.corpBaseInfoResponse.fullName
          }}<image
            src="../../static/img/user/ic_certificate.png"
            class="ub_rz"
          ></image
        ></view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState(['hasLogin', 'forcedLogin']),
  },
  data() {
    return {
      user: {},
      usert: {},
    };
  },
  onShow() {
    this.user = uni.getStorageSync('user').userInfoResponse;
    this.usert = uni.getStorageSync('user');
    console.log(this.user);
    if (!this.user.avatar) {
      this.user.avatar = '../../static/img/Default_avatar.png';
    }
  },
  methods: {
    ...mapMutations(['logout']),
    user_edit_company() {
      if (this.usert.corpBaseInfoResponse.fullName) {
        uni.navigateTo({
          url: '../user/user_edit_company',
        });
      } else {
        uni.navigateTo({
          url: '../user/user_select_add',
        });
      }
    },
    user_edit_mail() {
      uni.navigateTo({
        url: '../user/user_edit_mail',
      });
    },
    user_edit_phone() {
      uni.navigateTo({
        url: '../user/user_edit_phone',
      });
    },
    user_edit_sex() {
      uni.navigateTo({
        url: '../user/user_edit_sex',
      });
    },
    user_edit_name() {
      uni.navigateTo({
        url: '../user/user_edit_name',
      });
    },
    user_head() {
      uni.navigateTo({
        url: '../user/user_head',
      });
    },
    bindLogin() {
      uni.navigateTo({
        url: '../login/login',
      });
    },
    bindLogout() {
      this.logout();
      /**
       * 如果需要强制登录跳转回登录页面
       */
      if (this.forcedLogin) {
        uni.reLaunch({
          url: '../login/login',
        });
      }
    },
    navigateBack() {
      uni.navigateBack();
    },
  },
};
</script>

<style>
.ubs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 20rpx 0 0 0;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.ub {
  width: 720rpx;
  height: 90rpx;
  display: block;
  float: right;
  line-height: 90rpx;
  border-bottom: 1px solid #dddddd;
}
.ubs .ub:last-child {
  border: 0;
}
.ub_l {
  width: auto;
  height: auto;
  display: block;
  float: left;
  font-size: 34rpx;
  line-height: 90rpx;
  color: #000000;
  margin: 0rpx 0 0 0;
}
.ub_jt {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 32rpx 30rpx 0 0;
}
.ub_t {
  width: auto;
  height: 40rpx;
  display: block;
  float: right;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: right;
  color: #999999;
  margin: 25rpx 20rpx 0 0;
}
.ub_t image {
  width: 36rpx;
  height: 36rpx;
  display: block;
  float: right;
  margin: 0rpx 0rpx 0 6rpx;
}
.ub_tx {
  width: 114rpx;
  height: 114rpx;
  display: block;
  float: right;
  margin: 30rpx 20rpx 30rpx 0;
  border-radius: 8rpx;
}
.uba {
  height: auto;
}
.uba .ub_l {
  margin-top: 45rpx;
}
.uba .ub_jt {
  margin-top: 75rpx;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.tophr {
  width: 100%;
  height: 88rpx;
}
</style>
